package com.lagou.rabbitmq.web;

import com.lagou.rabbitmq.entity.Order;
import com.lagou.rabbitmq.entity.Response;
import com.lagou.rabbitmq.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName OrderController
 * @Description
 * @Author playboy
 * @Date 2021/8/28 7:47 下午
 * @Version 1.0
 **/
@RestController()
@RequestMapping("/order")
public class OrderController {
	private static Logger log = LoggerFactory.getLogger(OrderController.class);

	@Autowired
	private OrderService orderService;


	@RequestMapping("/pay/{id}")
	public Response pay(@PathVariable("id") String id){
		Response response = new Response();
		Order order = orderService.pay(id);
		if(order.getStatus().equals("03")){
			response.setFlag(true);
			response.setObj(order);
		}else{
			response.setFlag(false);
			response.setMsg("支付超时，订单已经取消");
			response.setObj(order);
		}
		return response;
	}

	@RequestMapping("/save")
	public Response save(@RequestBody Order order){
		order = orderService.save(order);
		Response response = new Response();
		response.setFlag(true);
		response.setObj(order);
		return response;
	}

	@RequestMapping("/{id}")
	public Response get(@PathVariable("id") String id){
		Order order = orderService.get(id);
		Response response = new Response();
		response.setFlag(true);
		response.setObj(order);
		return response;
	}



}
